/*
*   @Author: 1296
*   @Date: 2025-05-08
*   @Description: 工作台页面
*/
<template>
  <div class="dashboard-container">
    <CarouselComponent class="carousel-section" />
    <!--教师工作台-->
    <div class="dashboard-grid" v-if="isTeacher()">
      <div class="dashboard-item"
           v-for="(item, index) in dashboardItemsTea"
           :key="index"
           @click="handleItemClick(index)"
      >
        <el-button
            class="dashboard-button"
            type="primary"
            plain
            size="large"
        >
          <el-icon><component :is="item.icon"></component></el-icon>
        </el-button>
        <p class="button-text">{{ t(item.text) }}</p>
        <p class="button-desc">{{ t(item.description) }}</p>
      </div>
    </div>
    <!--学生工作台-->
    <div class="dashboard-grid" v-else>
      <div class="dashboard-item"
           v-for="(item, index) in dashboardItemsStu"
           :key="index"
           @click="handleItemClick(index)"
      >
        <el-button
            class="dashboard-button"
            type="primary"
            plain
            size="large"
        >
          <el-icon><component :is="item.icon"></component></el-icon>
        </el-button>
        <p class="button-text">{{ t(item.text) }}</p>
        <p class="button-desc">{{ t(item.description) }}</p>
      </div>
    </div>
  </div>
</template>

<script>
import CarouselComponent from '@/components/Carousel.vue';
import { Plus, Document, School, User, Switch, Unlock, Help, InfoFilled, Clock } from '@element-plus/icons-vue';
import { useRouter } from "vue-router";
import { useI18n } from 'vue-i18n'


export default {
  name: 'DashboardPage',
  components: {
    CarouselComponent
  },
  setup() {
    const router = useRouter();
    const { t } = useI18n();
    return { router, t };
  },
  data() {
    return {
      jobCode: sessionStorage.getItem('jobCode'),
      role: sessionStorage.getItem('role'),
      dashboardItemsTea: [
        { icon: Plus,
          text: 'dashboardItemsTea-text.plus',
          description: 'dashboardItemsTea-description.plus',
          path: '/:jobCode/personalPage',
          query: { section: 'publishCheckIn' }
        },
        { icon: Document,
          text: 'dashboardItemsTea-text.document',
          description: 'dashboardItemsTea-description.document',
          path: '/:jobCode/personalPage',
          query: { section: 'SignRecord' }
        },
        { icon: School,
          text: 'dashboardItemsTea-text.school',
          description: 'dashboardItemsTea-description.school',
          path: '/:jobCode/personalPage',
          query: { section: 'CourseManage' }
        },
        { icon: User,
          text: 'dashboardItemsTea-text.user',
          description: 'dashboardItemsTea-description.user',
          path: '/:jobCode/setting',
          query: { section: 'account' }
        },
        { icon: Switch,
          text: 'dashboardItemsTea-text.switch',
          description: 'dashboardItemsTea-description.switch',
          path: '/:jobCode/setting',
          query: { section: 'language' }
        },
        { icon: Unlock,
          text: 'dashboardItemsTea-text.unlock',
          description: 'dashboardItemsTea-description.unlock',
          path: '/:jobCode/setting',
          query: { section: 'resetPassword' }
        },
        { icon: Help,
          text: 'dashboardItemsTea-text.help',
          description: 'dashboardItemsTea-description.help',
          path: '/:jobCode/setting',
          query: { section: 'help' }
        },
        { icon: InfoFilled,
          text: 'dashboardItemsTea-text.infoFilled',
          description: 'dashboardItemsTea-description.infoFilled',
          path: '/:jobCode/setting',
          query: { section: 'about' }
        }
      ],
      dashboardItemsStu: [
        { icon: Clock,
          text: 'dashboardItemsStu-text.clock',
          description: 'dashboardItemsStu-description.clock',
          path: '/:jobCode/personalPage',
          query: { section: 'todoCheckIn' }
        },
        { icon: Document,
          text: 'dashboardItemsStu-text.document',
          description: 'dashboardItemsStu-description.document',
          path: '/:jobCode/personalPage',
          query: { section: 'attendanceRecord' }
        },
        { icon: School,
          text: 'dashboardItemsStu-text.school',
          description: 'dashboardItemsStu-description.school',
          path: '/:jobCode/personalPage',
          query: { section: 'myCourses' }
        },
        { icon: User,
          text: 'dashboardItemsStu-text.user',
          description: 'dashboardItemsStu-description.user',
          path: '/:jobCode/setting',
          query: { section: 'account' }
        },
        { icon: Switch,
          text: 'dashboardItemsStu-text.switch',
          description: 'dashboardItemsStu-description.switch',
          path: '/:jobCode/setting',
          query: { section: 'language' }
        },
        { icon: Unlock,
          text: 'dashboardItemsStu-text.unlock',
          description: 'dashboardItemsStu-description.unlock',
          path: '/:jobCode/setting',
          query: { section: 'resetPassword' }
        },
        { icon: Help,
          text: 'dashboardItemsStu-text.help',
          description: 'dashboardItemsStu-description.help',
          path: '/:jobCode/setting',
          query: { section: 'help' }
        },
        { icon: InfoFilled,
          text: 'dashboardItemsStu-text.infoFilled',
          description: 'dashboardItemsStu-description.infoFilled',
          path: '/:jobCode/setting',
          query: { section: 'about' }
        }
      ]
    }
  },
  methods: {
    handleItemClick(index) {
      let item = null;
      if (this.isTeacher()) {
        item = this.dashboardItemsTea[index];
      } else {
        item = this.dashboardItemsStu[index];
      }
      this.navigateTo(item.path, item.query);
    },
    navigateTo(path, query) {
      const fullPath = path.replace(':jobCode', this.jobCode);
      const route = {
        path: fullPath,
        query: query
      };
      this.router.push(route);
    },
    isTeacher() {
      console.log(this.role);
      return this.role === '1';
    }
  }
}
</script>

<style scoped>
.dashboard-container {
  width: 100%;
  padding: 20px;
  box-sizing: border-box;
}

.carousel-section {
  width: 85%;
  height: 350px;
  margin: 0 auto 30px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
  margin-top: 20px;
}

.dashboard-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 15px;
  border-radius: 8px;
  background-color: white;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  transition: transform 0.3s, box-shadow 0.3s;
}

.dashboard-item:hover {
  transform: translateY(-5px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.dashboard-button {
  margin-bottom: 10px;
  width: 80px;
  height: 80px;
}

.button-text {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 5px;
  color: #333;
}

.button-desc {
  font-size: 12px;
  color: #999;
  text-align: center;
}

@media (max-width: 768px) {
  .dashboard-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
</style>